﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Maticsoft.Common;

namespace Maticsoft.Web.Admin.Shopping
{
    public partial class CommentList : PageBase
    {
        string Key = string.Empty;
        string ChannelId = string.Empty;
        string Status = string.Empty;

        BLL.Comments bll = new BLL.Comments();
        protected void Page_Load(object sender, EventArgs e)
        {
            Check("shopping", "read");

            if (!string.IsNullOrEmpty(Request.QueryString["key"]))
            {
                Key = Request.QueryString["key"];
            }
            if (!string.IsNullOrEmpty(Request.QueryString["status"]))
            {
                Status = Request.QueryString["status"];
            }
            if (!IsPostBack)
            {
                BindData();
                BindSearch();
            }
            
        }

        protected void BindData()
        {
            string strWhere = "IsActive=1";
            if (!string.IsNullOrEmpty(Key))
            {
                strWhere += " and (title like '%" + Key + "%' or bookName like '%" + Key + "%')";
            }
            if (!string.IsNullOrEmpty(Status))
            {
                strWhere += " and ShowStatus=" + Status;
            }
            //strWhere += " order by commentId desc";
            int recordCount = bll.GetRecordCountV(strWhere);
            AspNetPager1.RecordCount = recordCount;
            DataSet ds = bll.GetListByPageV(strWhere, "commentId desc", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected void BindSearch()
        {
            if (!string.IsNullOrEmpty(Key))
            {
                txtKey.Value = Key;
            }
            if (!string.IsNullOrEmpty(Status))
            {
                ddlType.SelectedValue = Status;
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CommentList.aspx?status=" + ddlType.SelectedValue + "&key=" + txtKey.Value.Trim());
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Check("shopping", "del");

            string ids = txtIds.Value;
            if (!string.IsNullOrWhiteSpace(ids))
            {
                bll.DeleteByIds(ids);
            }
            MessageBox.ShowAndRedirect(this.Page, "删除成功", "CommentList.aspx?status=" + ddlType.SelectedValue + "&key=" + txtKey.Value.Trim());
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            string ids = txtIds.Value;
            if (!string.IsNullOrWhiteSpace(ids))
            {
                bll.AuditByIds(ids);
            }

            MessageBox.ShowAndRedirect(this.Page, "审核成功", "CommentList.aspx?status="+ddlType.SelectedValue+"&key=" + txtKey.Value.Trim());
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindData();
        }
    }
}